package com.finance.report.controller;

import com.finance.framework.controller.BaseController;
import com.finance.framework.controller.Result;
import com.finance.framework.lang.Page;
import com.finance.framework.lang.PageResultBO;
import com.finance.report.bean.pojo.SupplierSalary;
import com.finance.report.bean.pojo.SupplierSalaryList;
import com.finance.report.export.SupplierSalaryParse;
import com.finance.report.export.SupplierSalaryParseBean;
import com.finance.report.request.SupplierSalaryListReq;
import com.finance.report.service.ISupplierSalaryService;
import com.finance.util.export.ExportBuilder;
import com.finance.util.export.ExportFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


/**
 * @Author: lijinguo
 * 供货商月结报表
 */
@Controller
@RequestMapping("/report/suppliersalary")
public class SupplierSalaryController extends BaseController {
    @Resource
    private ISupplierSalaryService supplierSalaryService;

    @RequestMapping("/index.htm")
    public String index(){
        return "report/suppliersalary/index";
    }

    @RequestMapping("/list")
    public Result list(SupplierSalaryListReq form){
        Page page = Page.getInstance(form);
        SupplierSalaryList supplierSalary = new SupplierSalaryList();
        supplierSalary.setSupplierCode(form.getSupplierCode());
        supplierSalary.setSalaryMonth(form.getMonth());
        page.setParams(supplierSalary);
        PageResultBO<SupplierSalary> resultBO = supplierSalaryService.listByPage(page);
        return getSuccessResult(resultBO);
    }
    @RequestMapping("/export")
    public void export(SupplierSalaryListReq form, HttpServletResponse response){
        Page page = Page.getInstance(form);
        SupplierSalaryList list = new SupplierSalaryList();
        list.setSupplierCode(form.getSupplierCode());
        list.setSalaryMonth(form.getMonth());
        page.setParams(list);
        page.setLoadAll(true);
        PageResultBO<SupplierSalary> resultBO = supplierSalaryService.listByPage(page);
        try {
            ExportBuilder builder=new ExportBuilder
                    (SupplierSalaryParseBean.class,
                            new SupplierSalaryParse()
                    );
            ExportFactory factory= ExportFactory.getExportFactory(
                    builder );
            factory.setDataList(resultBO.getDataList()).outPut(response);

        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
    }

}
